//
//  CourseArrangementCell.m
//  Courses
//
//  Created by xxx on 15/1/15.
//  Copyright (c) 2015年 wtf. All rights reserved.
//

#import "CourseArrangementCell.h"
#import "UILabel+AutoSize.h"

const CGFloat kCourseArrangementCellHeight = 44;

@implementation CourseArrangementCell
{
    UILabel *_lblIndex;
    UILabel *_lblLessonName;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        CGFloat padding = 10;
        CGFloat radius = kCourseArrangementCellHeight - padding * 2;
        CGRect rect = AutoRectMake(20, padding, radius, radius, WTFAutoLayoutTypeRaw);
        _lblIndex = [[UILabel alloc] initWithFrame:rect];
        _lblIndex.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_lblIndex];
        
        UIView *back = [[UIView alloc] initWithFrame:rect];
        back.layer.cornerRadius = radius / 2;
        back.layer.borderColor = [UIColor blackColor].CGColor;
        back.layer.borderWidth = 1;
        [self.contentView addSubview:back];
        
        _lblLessonName = [[UILabel alloc] initWithFrame:AutoRectMake(60, padding, 200, radius, WTFAutoLayoutTypeBar)];
        [self.contentView addSubview:_lblLessonName];
    }
    
    return self;
}

- (void)setIndex:(NSUInteger)index
{
    _lblIndex.text = [NSString stringWithFormat:@"%lu", index + 1];
}

- (void)setLesson:(Lesson *)lesson
{
    _lblLessonName.text = lesson.lessonName;
}

@end
